#ifndef COMPONENTSTREEMODEL_H
#define COMPONENTSTREEMODEL_H

#include <QtCore>
#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>
#include <QSharedPointer>
#include <QStringList>
#include <QString>
#include <QMap>

#include "common.h"

class ComponentTreeItem;

class ComponentsTreeModel : public QAbstractItemModel
{
    Q_OBJECT

    typedef QAbstractItemModel super;  

public:
    ComponentsTreeModel(QObject* parent = 0);
    ComponentsTreeModel(const QString& data, QObject* parent = 0);
    ComponentsTreeModel(const QList<Component>& data, QObject* parent = 0);

    ~ComponentsTreeModel();

    // Этот набор функций должен быть реализован для иерархической Модели
    QVariant data(const QModelIndex &index, int role) const;
    Qt::ItemFlags flags(const QModelIndex &index) const;
    QVariant headerData(int section, Qt::Orientation orientation,
                        int role = Qt::DisplayRole) const;
    QModelIndex index(int row, int column, const QModelIndex &parent) const;
    QModelIndex parent(const QModelIndex &child) const;
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    // Дополнительная функция.
    bool removeRows (int row, int count, const QModelIndex& parent = QModelIndex() );

private:
    void setupModelData(const QStringList& lines, ComponentTreeItem* parent);
    void setupModelData(const QList<Component>& data, ComponentTreeItem* parent);
private:
    ComponentTreeItem* rootItem;
};

#endif // COMPONENTSTREEMODEL_H
